package com.prothink.threadadmindemo.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.RequiredArgsConstructor;

/**
 * @author mayanping
 * @title: Result
 * @projectName springboot-login
 * @description: TODO
 * @date 2024/2/2813:45
 */
@Data
@AllArgsConstructor
@RequiredArgsConstructor
public class Result<T> {
    private  int status;
    private String msg;
    private T data;

    public static <T> Result<T> success(){
        return success("成功", null);
    }

    public static <T> Result<T> success(T data){
        return success("成功", data);
    }


    public static <T> Result<T> success(String msg, T data){
        Result result = new Result<T>();
        result.status = 200;
        result.msg = msg;
        result.data = data;
        return result;
    }

    public static <T> Result<T> success(String msg, int status){
        Result result = new Result<T>();
        result.status = status;
        result.msg = msg;
        result.data = null;
        return result;
    }

    public static <T> Result<T> success(int status ,String msg, T data){
        Result result = new Result<T>();
        result.status = status;
        result.msg = msg;
        result.data = data;
        return result;
    }

    public static  <T> Result<T> failure(){
        return failure("失败");
    }

    public static  <T> Result<T> failure(String msg){
        return failure(msg, -1);
    }

    public static  <T> Result<T> failure(String msg, int status){
        Result result = new Result<T>();
        result.status = status;
        result.msg = msg;
        return result;
    }

}
